package com.trace.app.controller;


import com.trace.app.entity.Raw;
import com.trace.app.entity.ResponseResult;
import com.trace.app.service.RawService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Raw)表控制层
 *
 * @author lionkliu
 * @since 2024-04-21 13:27:18
 */
@RestController
@RequestMapping("raw")
public class RawController {

    @Resource
    private RawService rawService;

    @GetMapping("/page")
    public ResponseResult selectPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize) {
        return rawService.selectPage(pageNum, pageSize);
    }

    @GetMapping("/getLabelValue")
    public ResponseResult getLabelValue() {
        return rawService.getLabelValue();
    }

    @GetMapping("/getSupplierByRawId/{rawId}")
    public ResponseResult getSupplierByRawId(@PathVariable("rawId") Integer rawId) {
        return rawService.getSupplierByRawId(rawId);
    }

    @GetMapping("/search")
    public ResponseResult search(@RequestParam("pageNum") Integer pageNum,
                                 @RequestParam("pageSize") Integer pageSize,
                                 @RequestParam("name") String name) {
        return rawService.search(pageNum, pageSize, name);
    }

    @GetMapping("/list")
    public ResponseResult list() {
        return ResponseResult.okResult(rawService.list());
    }

    @GetMapping("{id}")
    public ResponseResult selectOne(@PathVariable Integer id) {
        return rawService.selectOne(id);
    }

    @PostMapping
    public ResponseResult insert(@RequestBody Raw raw) {
        return rawService.insertOne(raw);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Raw raw) {
        return rawService.updateOne(raw);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return rawService.deleteById(id);
    }

}
